//
//  CJExten+Int.swift
//  CJCore
//
//  Created by 陈警卫 on 2024-06-13.
//

import Foundation

public protocol CJIntProtocol: FixedWidthInteger, CVarArg {}

extension Int: CJIntProtocol {}
extension UInt: CJIntProtocol {}
extension UInt8: CJIntProtocol {}
extension UInt16: CJIntProtocol {}
extension UInt32: CJIntProtocol {}

public extension CJIntProtocol {
    
    /// 转16进制字符串
    var cj_hexString: String {
        return String(format: "%lX", self)
    }
    
    /// 转2进制字符串
    var cj_binaryString: String {
        return String(self, radix: 2)
    }
    
    /// 转Data
    /// bigEndian大小端 默认 false
    func cj_data(_ bigEndian: Bool = false) -> Data {
        var value = self
        if bigEndian {
            value = Self(bigEndian: value)
        }
        let data = Data(bytes: &value, count: cj_sizeof(value))
        return data
    }
}
